//
//  TAttachement.m
//  TestDemo
//
//  Created by fengxijun on 5/10/16.
//  Copyright © 2016 goappbox. All rights reserved.
//

#import "TAttachement.h"

@implementation TAttachement

- (instancetype) initWithContentFile:(NSString *)filepath
{
    self = [super init];
    if (self) {
//        self.fileWrapper = [[NSFileWrapper alloc] initWithURL:[NSURL fileURLWithPath:filepath] options:NSFileWrapperReadingImmediate error:nil];
        self.image = [UIImage imageWithContentsOfFile:filepath];
    }
    return self;
}

- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex
{
    NSLog(@"lineFrag : %@ -> position : %@ -> charIndex : %lu",NSStringFromCGRect(lineFrag),NSStringFromCGPoint(position),(unsigned long)charIndex);
    CGRect rect = CGRectZero;
    if (self.image.size.width > textContainer.size.width) {
        rect = CGRectMake(0.f, 0.f, textContainer.size.width, 300.f);
    } else {
        rect = CGRectMake(10.f, 0.f, self.image.size.width, lineFrag.size.height);
    }
    return rect;
}

@end
